<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view>
		<view>
			<view>组件测试</view>
			<view>
				<view>test组件</view>
				<test v-if="flag" :title="title" @myEven="getNum"></test>
				<button type="primary" @click="checkTest">切换test组件</button>
			</view>
			<view>
				<view>兄弟组件传数据</view>
				<test-a></test-a>
				<test-b></test-b>
			</view>
			<view>
				<view>扩展组件</view>
				<uni-calendar
							:insert="true"
							:lunar="true" 
							:start-date="'2019-3-2'"
							:end-date="'2019-5-20'"
							@change="change"
							 >
						</uni-calendar>
			</view>
			
		</view>
		<h1>目录</h1>
		<view>
			<view>导航跳转-静态</view>
			<p>https://uniapp.dcloud.io/component/navigator</p>
			<center>
				<navigator url="/pages/detail/detail?id=80&age=19">详情页</navigator>
				<navigator url="/pages/message/message" open-type="switchTab">信息页</navigator>
				<navigator url="/pages/detail/detail" open-type="redirect">redirect详情页</navigator>
			</center>
			
			<hr/>
			<view>导航跳转-编程式</view>
			<p>https://uniapp.dcloud.io/api/router?id=navigateto</p>
			<center>
				<button size="mini" @click="goDetail(80,19)">跳转之详情页</button> <br/>
				<button size="mini" @click="goMessage">跳转至信息页</button> <br/>
				<button size="mini" type="primary" @click="redirectDetail()">跳转到详情页并关闭当前页面</button> <br/>
				<button size="mini" type="primary" @click="addToCar">加入购物车</button> <br/>
			</center>
		</view>
	</view>
</template>

<script>
	import test from '../../components/test.vue'
	import testA from '../../components/a.vue'
	import testB from '../../components/b.vue'
	import uniCalendar from '@/components/uni-calendar/uni-calendar.vue'
	export default {
		data() {
			return {
				title: 'Hello',
				num: 0,
				flag: true
			}
		},
		onLoad(options) {
			console.log('页面加载了', options)
		},
		onShow() {
			console.log('页面显示了')
		},
		onReady() {
			console.log('页面初次渲染完成了')
		},
		onHide() {
			console.log('页面隐藏了')
		},
		methods: {
			checkTest() {
				this.flag = !this.flag
			},
			getNum(num) {
				console.log(num)
				this.num = num
			},
			change(e) {
				console.log('出发了change', e)
			},
			goDetail (n,m) {
				console.log(n,m)
				console.log(`id=${n}&age=${m}`)
				uni.navigateTo({
					// url: '/pages/detail/detail?id=80&age=19'
					url: `/pages/detail/detail?id=${n}&age=${m}`
				})
			},
			goMessage () {
				uni.switchTab({
					url: '/pages/message/message'
				})
			},
			redirectDetail () {
				uni.redirectTo({
					url: '/pages/detail/detail'
				});
			},
			addToCar () {
				uni.$emit('updateCart',{
					id: 10,
					name: '贸易'
				})
			}
		},
		components: {
			test,
			"test-a": testA,
			"test-b": testB,
			uniCalendar
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.logo {
		height: 200rpx;
		width: 200rpx;
		margin-top: 200rpx;
		margin-left: auto;
		margin-right: auto;
		margin-bottom: 50rpx;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}
</style>
